package com.kly.user.db.dao.impl;
import com.fqgj.common.base.AbstractBaseMapper;
import com.fqgj.common.utils.CollectionUtils;
import com.fqgj.common.utils.StringUtils;
import com.google.common.collect.Maps;
import com.kly.user.db.dao.UserMsgForChatterDao;
import com.kly.user.db.entity.UserMsgForChatterEntity;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
* User: linqu
* Date: 2023-10-26
* Time: 17:05:57.109
*/

@Repository
public class UserMsgForChatterDaoImpl extends AbstractBaseMapper<UserMsgForChatterEntity> implements UserMsgForChatterDao {

    @Override
    public UserMsgForChatterEntity getUserMsgForChatter(String chatterUserCode, String fromUserCode, String toUserCode) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("chatterUserCode", chatterUserCode);
        map.put("fromUserCode", fromUserCode);
        map.put("toUserCode", toUserCode);
        final List<UserMsgForChatterEntity> userMsgForChatterEntities = this.selectByParams(map);
        if (CollectionUtils.isEmpty(userMsgForChatterEntities)) {
            return null;
        }
        return userMsgForChatterEntities.get(0);
    }

    @Override
    public List<UserMsgForChatterEntity> queryByUserCode(String chatterUserCode, String fromUserCode, String toUserCode) {
        Map<String, Object> map = Maps.newHashMap();
        if (StringUtils.isNotEmpty(chatterUserCode)) {
            map.put("chatterUserCode", chatterUserCode);
        }
        if (StringUtils.isNotEmpty(fromUserCode)) {
            map.put("fromUserCode", fromUserCode);
        }
        if (StringUtils.isNotEmpty(toUserCode)) {
            map.put("toUserCode", toUserCode);
        }
        final List<UserMsgForChatterEntity> userMsgForChatterEntities = this.selectByParams(map);
        if (CollectionUtils.isEmpty(userMsgForChatterEntities)) {
            return null;
        }
        return userMsgForChatterEntities;
    }
}